<template>
  <div class="plr20 mt80">
    <!-- <mt-field :attr="{ maxlength: 11 }" placeholder="请输入手机号" type="tel" v-model="form.userName"></mt-field> -->
    <!-- <mt-field class="b-bott" placeholder="请输入密码" type="password" v-model="form.passWord"></mt-field>
    <mt-button class="mt20" type="primary" @click="login" size="large">登陆</mt-button>
    <mt-button class="mt10 bgcolor2" type="primary" @click="reg" size="large">注册</mt-button>
    <foot-Tab></foot-Tab> -->
  </div>
</template>

<script>
import footTab from '@/components/footTab'
import { Http } from '@/api/api'
import { znk } from '@/util/public'
import { validate } from '@/util/validate'
export default {
  components: { 'foot-Tab': footTab },
  data () {
    return {
      toastObj: null,
      phoneState: null,
      form: {
        'userName': null,
        'passWord': null
      }

    }
  },
  methods: {
    login () {
      let status = validate.checkVliate([
        { nameFun: 'isPhone', value: [this.form.userName] },
        { nameFun: 'password', value: [this.form.passWord] }
      ])
      if (status) {
        this.$indicator.open()
        Http('post', '/aiyu/applogin/appLoginIn', this.form).then((data) => {
          if (data.code !== '0000') {
            validate.msg(data.msg, 0)
          } else {
            znk.setCookie('token', data.data.userToken)
            znk.setCookie('userId', data.data.userId)
            znk.setCookie('userName', data.data.userName)
            this.$store.commit('USERINFO', data.data)
            this.$router.push({
              path: '/aiyu/index'
            })
          }
          this.$indicator.close()
        })
      }
    },
    reg (val) {
      this.$router.push({
        path: '/aiyu/reg'
      })
    },
    footTab () {
      console.log('dianji', this.selected)
    }
  },
  mounted () {
    // let that = this
    // that.init()
    // this.username = this.$store.state.userinfo.data.name
  },
  watch: {
    selected: {
      handler (val) {
        if (val === 'tab1') {
          this.img[0] = require('@/assets/img/icon1_act.png')
          this.img[1] = require('@/assets/img/icon2.png')
        } else if (val === 'tab2') {
          this.img[0] = require('@/assets/img/icon1.png')
          this.img[1] = require('@/assets/img/icon2_act.png')
        }
        // let phoneMsg = znk.isPhone(val)
        console.log(val)
      }
    }
  }
}
</script>
<style scoped>
</style>
